const db = require("../../config/db")

module.exports = {
    // 网站设置更新
    webupdated: (archivalLink, webTitle, archivalNum, informText) => {

        let sql = `UPDATE db_website_set SET web_name='${webTitle}',archival_link='${archivalLink}',inform_text='${informText}',archival_num='${archivalNum}' WHERE id=1;`
        return db.promisePool.query(sql)
    },

    // 登录接口
    loginrequest: () => {
        let sql = `SELECT * FROM db_admin_user WHERE id = '1'`;
        return db.promisePool.query(sql)

    },

    // 更改后台管理账号密码
    updateuser: (user_account, user_password) => {
        let sql = `UPDATE db_admin_user SET user_account='${user_account}',user_password='${user_password}' WHERE id = '1'`;
        return db.promisePool.query(sql)
    },

    // 文章管理 请求所有博客
    allblog: () => {
        let sql = `SELECT * FROM db_blog_item ORDER BY id DESC`;
        return db.promisePool.query(sql)
    },

    // 文章删除
    deleteitem: (id) => {
        let sql = `DELETE FROM db_blog_item WHERE id = '${id}'`;
        return db.promisePool.query(sql)
    },

    // 更新文章
    updateitem: (contentId, title, contentHtml, createTimer, articleClassVal, CoverImageurl, author, articleTagVal, articledescribe) => {
        let sql = `UPDATE db_blog_item SET content_id='${contentId}',title='${title}',content_html='${contentHtml}',article_class='${articleClassVal}',create_timer='${createTimer}',cove_image='${CoverImageurl}',author='${author}',article_tag='${articleTagVal}',article_describe='${articledescribe}' WHERE content_id = '${contentId}'`;
        return db.promisePool.query(sql)
    },

    // 搜索文章
    search: (title) => {
        // 
        let sql = `SELECT * FROM  db_blog_item WHERE (title LIKE '${title}%')or (title LIKE '%${title}%') `;
        return db.promisePool.query(sql)
    },

    // 添加轮播图
    addbanner: (imageurl, linkUrl, bannerName) => {
        let sql = `insert into db_banner (banner_name,image_url,link_url) values('${bannerName}','${imageurl}','${linkUrl}')`;
        return db.promisePool.query(sql)

    },

    // 删除轮播图
    deletebanner: (id) => {
        let sql = `DELETE FROM db_banner WHERE id = ${id}`;

        return db.promisePool.query(sql)
    },

    // 请求所有轮播图
    getbanner: () => {
        let sql = `SELECT * FROM db_banner ORDER BY id DESC`;
        return db.promisePool.query(sql)
    },

    // 请求所有分类
    getblogclass: () => {
        let sql = `SELECT * FROM db_article_class ORDER BY id DESC`;
        return db.promisePool.query(sql)
    },

    // 添加单个分类
    addclassify: (classNameVal) => {
        let sql = `INSERT INTO db_article_class(article_class) VALUES ('${classNameVal}')`;
        return db.promisePool.query(sql)
    },

    // 删除单个分类
    deleteblogclass: (id) => {
        let sql = `DELETE FROM db_article_class WHERE id = ${id}`;
        return db.promisePool.query(sql)
    },

    // 评论列表
    commentlist: () => {
        let sql = `SELECT * FROM db_comment_first ORDER BY id DESC`;
        return db.promisePool.query(sql)
    },

    // 删除评论
    deletecomment: (id) => {
        console.log(id);
        let sql = `DELETE FROM db_comment_first WHERE id = '${id}'`
        return db.promisePool.query(sql)
    },

    // 搜索评论
    searchcomment: (searchValue) => {
        let sql = `SELECT * FROM  db_comment_first WHERE (leave_word LIKE '${searchValue}%')or (leave_word LIKE '%${searchValue}%')`;
        return db.promisePool.query(sql)
    },

    // 回复留言板
    replymessage: (id, replyVal) => {
        // let addlook = `UPDATE db_blog_item SET look_count=look_count+1 WHERE id ='${itemId}'`;
        let sql = `UPDATE db_message_board SET reply_text='${replyVal}' WHERE id ='${id}'`;
        return db.promisePool.query(sql)

    }
}  